package com.taiji.dianthus.util;

import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static com.taiji.dianthus.common.Constant.D_SEPARATOR;

/**
 * @ClassName DStringUtil
 * @Description 字符串工具类
 * @Author H.M
 * @Date 2020/6/13
 */
public class DStringUtil {

    /**
     * 拼接字符串转换list
     * @param ids
     * @return
     */
    public static List<String> getIdArray(String ids) {
       return getIdArray(ids,D_SEPARATOR);
    }

    /**
     * 拼接字符串转换list
     * @param ids
     * @param separator 分隔符
     * @return
     */
    public static List<String> getIdArray(String ids,String separator) {
        if (StringUtils.isEmpty(ids)) {
            return null;
        }
        String [] idArray= ids.split(separator);
        if (null == idArray || idArray.length == 0) {
            return null;
        }else {
            return Arrays.asList(idArray);
        }
    }

    public static String[] removeNullStringArray(String[] arrayString) {
        List<String> list1 = new ArrayList<String>();
        for (int i = 0; i < arrayString.length; i++) {
            if (!StringUtils.isEmpty(arrayString[i])) { //过滤掉数组arrayString里面的空字符串
                list1.add(arrayString[i]);
            }
        }
        return list1.toArray(new String[0]);
    }
}
